package com.sunxu.exercise2;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * ${DESCRIPTION}
 *
 * @author Sun
 * @create 2017-07-31-23:35
 */
public class DefaultControllerTest {
    private DefaultController  controller;

    @Before
    public void setUp() throws Exception {
        controller = new DefaultController();
    }

    @Test
    public void testAddHandler() {
        Request request = new SampleRequest();
        RequestHandler handler = new SampleHandler();
        controller.addHandler(request, handler);
        RequestHandler handler1 = controller.getHandler(request);
        assertSame("yes", handler1, handler);
    }

    @Test
    public void testProcessRequest() {
        Request request = new SampleRequest();
        RequestHandler handler = new SampleHandler();
        controller.addHandler(request, handler);
        Response response = controller.processRequest(request);
        assertNotNull("must not return a null response", response);
        assertEquals("Response should be of type SampleResponse", SampleResponse.class, response.getClass());
    }
}